package com.augurit.gzcgwsp.sendNotice.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.augurit.gzcgwsp.csshlj.dao.CsshljCzDao;
import com.augurit.gzcgwsp.sendNotice.service.ISaveApprovalIdService;
import com.augurit.gzcgwsp.sendNotice.service.IYwWebserviceInfoService;
import com.augurit.common.syslog.tool.SysTraceLogWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Service
@Transactional
public class SaveApprovalIdServiceImpl implements ISaveApprovalIdService{
	Logger logger = (Logger) LoggerFactory.getLogger(SaveApprovalIdServiceImpl.class);
	@Autowired
	private CsshljCzDao csshljCzDao;
	
	@Autowired
	private IYwWebserviceInfoService ywWebserviceInfoService;
	/**
	 * 把预受理号保存到相应的业务表的案件里面
	 * @param acceptNo 业务受理号
	 * @param approvalId 预受理号 长的
	 * @param businessCode 业务编码
	 * @return true或者false
	 */
	public boolean saveApprovalId(String acceptNo,String approvalId,String businessCode){
		try {
			String tableName = "";
			if("04_YW_RQ_SSGD_SQB".endsWith(businessCode)){
				tableName = "YW_RQ_SSGD_SQB";
			}else if("04_YW_CS_LJ_CZ".endsWith(businessCode)){
				tableName = "SHLJ_CZ_V1";
			}else if("04_YW_HW_SCSLJ_JYFW".endsWith(businessCode)){
				tableName = "SYSHLJ_V1";
			}else if("04_YW_SS_CG_GC".endsWith(businessCode)){
				tableName = "SS_CCGBSQB_V1";
			}else if("04_YW_HW_LCSLJ_JYFW".endsWith(businessCode)){
				tableName = "HW_SHLJQS_V1";
			}else if("04_YW_HW_SH_SQB".endsWith(businessCode)){
				tableName = "YW_JG_HWGG_SQB";
			}else if("04_YW_RQ_JYXK_GD".endsWith(businessCode)){
				tableName = "YW_RQ_QYJYXK";
			}else if("04_YW_RQ_JYXK_PZ".endsWith(businessCode)){
				tableName = "YW_RQ_QYJYXK";
			}else if("04_YW_RQ_QYZZ_INFO".endsWith(businessCode)){
				tableName = "YW_RQ_QYZZ_INFO";
			}else if("04_YW_SR_CSDL_WJ".endsWith(businessCode)){
				tableName = "SR_DLWJSQB_V4";
			}else if("04_YW_SR_CSDL_LSZY".endsWith(businessCode)){
				tableName = "SR_DLZYSQB_V1";
			}else if("04_YW_YNC_JZ_FQ_PS".endsWith(businessCode)){
				tableName = "YW_YN_JZFQWCZC_PFSN";
			}else if("04_YW_YNC_JZ_FQ_XN".endsWith(businessCode)){
				tableName = "YW_YN_JZFQWCZC_XN";
			}else if(businessCode.contains("04_YW_YNC_JZ_FQ_YS")){
				tableName = "YW_YN_JZFQWCZC_JBXX";
			}else if("".endsWith(businessCode)){
				tableName = "";
			}else if("".endsWith(businessCode)){
				tableName = "";
			}
			String sql = "update " + tableName + " t set t.approval_no='"+approvalId+"' where t.accept_no='"+acceptNo+"'";
			csshljCzDao.updateDateBase(sql);
			System.out.println("123456");
			ywWebserviceInfoService.changStateToNullByAcceptNo(acceptNo,approvalId);
			return true;
		} catch (Exception e) {
			logger.error("(接口)保存approvalId接口异常"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);
			e.printStackTrace();
			return false;
		}
	}
}
